<!--
 * @description 小组活动报名统计
 * @author dumeng
 * @date 2021/9/17
 -->
<template>
  <section class="group-activity-apply-record">

    <el-collapse-transition>
      <section v-show="searchshow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model.trim="listQuery.userRealname"
          placeholder="输入姓名搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>
        </section>
      </section>
    </el-collapse-transition>
    <el-collapse-transition>
      <section v-show="!searchshow" class="main-search separate">
        <section class="search-inner">
          <el-row>
            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">姓名</div>
                <el-input
                  v-model.trim="search.userName"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入姓名搜索"
                />
              </section>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">证件号</div>
                <el-input v-model.trim="search.idCard" style="width: 80%" class="filter-item" placeholder="请输入证件号搜索" />
              </div>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">手机号码</div>
                <el-input
                  v-model.trim="search.phoneNum"
                  style="width: 80%"
                  class="filter-item"
                  placeholder="请输入手机号码搜索"
                />
              </div>
            </el-col>

          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>报名详情</span>
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px" @click="exportFun">导出</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="backFun">返回</el-button>
      </section>
    </section>
    <div class="classify-tab">
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in checkList" :key="item.id" :label="item.name" :name="item.id" />
      </el-tabs>
    </div>
    <section class="main-table">
      <v-table
        :list="list"
        tag="groupActivityApplyRecord"
        :selection="false"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
      />
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </section>
  </section>
</template>
<script>
import {
  signQueryPage,
  maskAPI4apply,
  noMaskAPI4apply
} from '../api/activity'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import CryptoJS from '@/utils/aesJiaJM'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { mapGetters } from 'vuex'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'

export default {
  name: 'GroupActivityApplyRecord',
  components: {
    VTable,
    Pagination
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        userName: ''
      },
      search: {
        userName: '',
        phoneNum: '',
        idCard: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      view: '/API-DOCUMENT/document/file/download?id=',
      searchshow: true,
      gid: '', // 小组id
      aid: '', // 活动id
      activeTab: '',
      checkList: [
        {
          name: '全部',
          id: ''
        },
        {
          name: '申请中',
          id: 'BMZT_SQZ'
        }, {
          name: '申请通过',
          id: 'BMZT_SQTG'
        },
        {
          name: '申请未通过',
          id: 'BMZT_SQBTG'
        }
      ]

    }
  },
  computed: {
    ...mapGetters([
      'backUrl'
    ])
  },
  created() {
    if (this.$route.query.ai) {
      this.aid = this.$route.query.ai
      this.gid = this.$route.query.gi ? this.$route.query.gi : ''
      this.getList()
    } else {
      this.$message.error('页面参数错误')
      this.$router.back()
    }
  },
  methods: {
    backFun() {
      if (this.backUrl !== null) { // 如果是小组管理跳入的
        this.$router.push(this.backUrl)
      } else {
        this.$router.push({ path: this.$filterPath('activityManage'), query: { t: this.$route.query.t }})
      }
    },
    handleTabClick() {
      this.listQuery.query = 1
      this.getList()
    },
    exportFun() {
      const query = {
        activityId: this.aid,
        registrationStatus: this.activeTab === '0' ? '' : this.activeTab
      }
      if (this.searchshow) {
        query['userRealname'] = this.listQuery.userName
      } else {
        query['userRealname'] = this.search.userName
        query['userPhone'] = this.search.phoneNum
        query['userIdnumber'] = this.search.idCard
      }
      exportCheck('STAFF_SERVICE_INTERESTGROUP', this.aid, maskAPI4apply, noMaskAPI4apply, exportSign(query).obj, '活动报名情况.xlsx')
    },
    filtercolumn(scope, item) {
      if (item === 'userPhone' || item === 'userIdnumber') {
        return scope.row[item] ? CryptoJS.$aesJieM(scope.row[item]) : '--'
      } else {
        return scope.row[item]
      }
    },
    handleReset() {
      this.listQuery.page = 1
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      const query = {
        groupId: this.gid,
        activityId: this.aid,
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        registrationStatus: this.activeTab === '0' ? '' : this.activeTab
      }
      if (this.searchshow) {
        query['userRealname'] = this.listQuery.userRealname
      } else {
        query['userRealname'] = this.search.userRealname
        query['userPhone'] = CryptoJS.$aesJiaM(this.search.phoneNum)
        query['userIdnumber'] = CryptoJS.$aesJiaM(this.search.idCard)
      }
      return new Promise((resolve, reject) => {
        signQueryPage(query).then(response => {
          this.list = response.data.data.rows || []
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">
@import '@/styles/mixin.scss';

$dark_gray: #bfced6;

.group-activity-apply-record {
  padding: 10px;

  .main-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            &.el-date-editor input {
              padding-left: 30px;
            }

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .classify-tab {
    width: 100%;
    margin-bottom: 10px;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;

    .el-tabs__nav-wrap::after {
      display: none;
    }

    .el-tabs__header {
      margin: 0;
    }
  }
  .main-buttons {
    display: flex;
    line-height: 36px;
    margin: 10px 0;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);

      .num {
        @include font-color($mainColor);
      }
    }
  }
}
</style>
